package Homework;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

public class PuKe {

	public static void main(String[] args) {
		//准备牌
		HashMap<Integer, String> pokerMap = new HashMap<>();
		String[] colors={"♠","♣","♦","♥"};
		String[] numbers={"2","A","K","Q","J","10","9","8","7","6","5","4","3"};	
		
		int key = 0;
		for(String num:numbers){
			for(String color:colors){
				pokerMap.put(key++, color+num);
			}
		}
		pokerMap.put(key++, "大王");
		pokerMap.put(key, "小王");	
		//转为list
		List<Entry<Integer,String>> pokerList = new ArrayList<Entry<Integer,String>>(pokerMap.entrySet());
		
		//比较器
		Comparator<Entry<Integer,String>> comparator = new Comparator<Entry<Integer,String>>() {

			@Override
			public int compare(Entry<Integer,String> o1, Entry<Integer,String> o2) {
				return o1.getKey()-o2.getKey();
			}
		};
		
		//洗牌
		Collections.shuffle(pokerList);
		
		//摸牌
		Player p1 = new Player();
		Player p2 = new Player();
		Player p3 = new Player();
		p1.setName("老王1");
		p2.setName("老王2");
		p3.setName("老王3");
		
		ArrayList<String> dipai = new ArrayList<String>();
		for(int i = 0;i<pokerList.size();i++){
			if(i>=51){
				dipai.add(pokerList.get(i).getValue());
			}else if(i%3==0){
				p1.getPoker().add(pokerList.get(i));
			}else if(i%2==0){
				p2.getPoker().add(pokerList.get(i));
			}else{
				p3.getPoker().add(pokerList.get(i));
			}
		}		
		
		//看牌
		Collections.sort(p1.getPoker(), comparator);
		Collections.sort(p2.getPoker(), comparator);
		Collections.sort(p3.getPoker(), comparator);
		System.out.println(p1.getName()+"的牌："+p1.watchPokerValues());
		System.out.println(p2.getName()+"的牌："+p2.watchPokerValues());
		System.out.println(p3.getName()+"的牌："+p3.watchPokerValues());
		System.out.println("底牌："+dipai);
	}

}
